package zhishu.iceyyy.com.bxq_2500.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import zhishu.iceyyy.com.bxq_2500.R;
import zhishu.iceyyy.com.bxq_2500.base.BaseApplication;
import zhishu.iceyyy.com.bxq_2500.base.Base_Z_Adapter;

/**
 * Created by Administrator on 2019/7/10.
 */

public class HorizontalListViewAdapter extends Base_Z_Adapter {
    private int checked = -1;

    public void setChecked(int checked) {//设定一个选中的标志位，在activity中传入值。
        this.checked = checked;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HorizontalListViewAdapter.Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(BaseApplication.getInstance())
                    .inflate(R.layout.tab_item_1_test, null);
            holder = new HorizontalListViewAdapter.Holder();
            holder.value = (Button) convertView
                    .findViewById(R.id.roundButton);
            convertView.setTag(holder);
        } else {
            holder = (HorizontalListViewAdapter.Holder) convertView.getTag();
        } //计算每条的宽度

        String s = (String) getItem(position);
        holder.value.setText(s);

        if (checked == position) {//如果点击的项目正好是position这一项
    /*将前面的小圆设置为选中状的图标*/
            holder.value.setTextColor(BaseApplication.getInstance().getResources().getColor(R.color.white));
            holder.value.setBackgroundColor(BaseApplication.getInstance().getResources().getColor(R.color.colorPrimaryDark));
        } else {
            holder.value.setTextColor(BaseApplication.getInstance().getResources().getColor(R.color.black));
            holder.value.setBackgroundColor(BaseApplication.getInstance().getResources().getColor(R.color.gray));
        }
//        holder.tv.setText(strings[position]);
        return convertView;
    }

    public class Holder {


        Button value;


    }
}



